package com.alipay.sporadic.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.demo.trade.model.GoodsDetail;
import com.alipay.demo.trade.model.builder.AlipayTradePayRequestBuilder;
import com.alipay.demo.trade.model.builder.AlipayTradeQueryRequestBuilder;
import com.alipay.demo.trade.model.builder.AlipayTradeRefundRequestBuilder;
import com.alipay.demo.trade.model.result.AlipayF2FPayResult;
import com.alipay.demo.trade.model.result.AlipayF2FQueryResult;
import com.alipay.demo.trade.model.result.AlipayF2FRefundResult;
import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.sporadic.configuration.AliPayProperties;
import com.alipay.sporadic.service.OrderService;
import com.alipay.sporadic.service.SporadicPayService;
import dto.DishesDTO;
import dto.OrderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vo.ResponseData;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @program: sporadic
 * @description:
 * @author: LHD   QQ:1727865856
 * @create: 2019-10-30 21:09
 **/
@RestController
@RequestMapping("/alipay")
public class AlipayController {
    @Autowired
    private SporadicPayService sporadicPayService;

    @GetMapping("/test")
    public String test() {
        return sporadicPayService.test();
    }


    @PostMapping("/pay")
    public ResponseData<String> alipay(String paymentCode, String orderNo) throws InterruptedException {
        return sporadicPayService.alipay(paymentCode, orderNo);
    }


    @GetMapping("/query")
    public String payquery(String orderNo) {
        return sporadicPayService.payquery(orderNo);
    }

    @PostMapping("/rqpay")
    public ResponseData<String> pay(String orderNo){
        return sporadicPayService.qrpay(orderNo);
    }

    @GetMapping("/queryQrpay")
    public ResponseData<String> queryQrpay(String orderNo,String tradeNo){
        return sporadicPayService.queryQrpay(orderNo);
    }

    @PostMapping("/refund")
    public String refund(String orderNo) {
        return sporadicPayService.refund(orderNo);
    }

    @Autowired
   private OrderService orderService;

    @GetMapping("/test1")
    public ResponseData<List<DishesDTO>> test(String orderId) {
        ResponseData<List<DishesDTO>> listResponseData =null;
        try {
            listResponseData = orderService.selectByOrderIdDis(orderId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listResponseData;
    }
}
